//
//  ManagerService.m
//  Etion
//
//  Created by  user on 11-1-19.
//  Copyright 2011 GuangZhouXuanWu. All rights reserved.
//

#import "XLGManagerService.h"

#import "GWService.h"

@implementation XLGManagerService
{
    CGWService *_service;
}

-(id)initWithManagerServiceDelegate:(id<XLGManagerServiceDelegate>)domdelegate
{
	return [super initWithDataOperationManagerDelegate:domdelegate];
}

-(id)initWithManagerServiceDelegate:(id<XLGManagerServiceDelegate>)domdelegate otherms:(XLGManagerService *)mservice
{
	return [super initWithDataOperationManagerDelegate:domdelegate AttachDOM:mservice];
}

- (void)serviceWith:(NSString*)szIP port:(int)nPort GWService:(void(^)(CGWService *service))block
{
    if(_service == nil)
    {
        _service = [[CGWService alloc]initWithSocketChannel:szIP port:nPort];
        block(_service);
        ReleaseObj(_service);
    }
}

-(BOOL)attachManagerService:(NSArray*)arService
{
    return [super attachDataOperationManager:arService];
}

-(void)detachManagerService
{
    [super detachAllDataOperationManager];
}

-(void)detachManagerService:(XLGManagerService*)ms
{
    if(ms!=nil)
        [super detachDataOperationManager:[NSArray arrayWithObject:ms]];
}

-(BOOL)terminateRequest
{
    return [super terminateRequest];
}

-(BOOL)stopRequest
{
    return [super stopRequest];
}

-(BOOL)terminateSelfRequest:(BOOL)bRejectrequest
{
    if(_service == nil)
        return YES;
    return [_service terminateService];
}

//- (int)getGWService:(int(^)(CGWService *service))block
//{
//    if(m_service==nil)
//        m_service=[CGWService new];
//    int nResult=block(m_service);
// //   ReleaseObj(m_service);
//    return nResult;
//}

-(CGWService*)service
{
    if(_service == nil)
        _service = [CGWService new];

    return _service;
}

-(void)dealloc
{
    [_service release_mm];
	superdealloc_mm;
}

@end
